package modules.majiang.viewManager
{
	/**
	 *
	 * @author xumin.xu 2013-1-28
	 */

	import com.netease.protobuf.UInt64;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import modules.GameEvent;
	import modules.ViewManager;
	import modules.majiang.MajiangEvent;
	import modules.majiang.data.BonusPotsData;
	import modules.majiang.data.TableDataModel;
	import modules.majiang.data.TablesDataManager;
	import modules.majiang.view.BonusPotViewProxy;

	public class BonusPotViewManager extends ViewManager
	{
		private var tableId:UInt64;

		private var bonusPotViewProxyList:Array;

		/**
		 * 奖池数据
		 **/
		private var bonusPotsData:BonusPotsData;

		public function BonusPotViewManager(tableId:UInt64,tableView:MovieClip)
		{
			super();
			this.tableId = tableId;

			this.mainUI = tableView;

			bonusPotViewProxyList = [new BonusPotViewProxy(tableView.bonusPot_1), //
				new BonusPotViewProxy(tableView.bonusPot_2), //
				new BonusPotViewProxy(tableView.bonusPot_3), //
				new BonusPotViewProxy(tableView.bonusPot_4), //
				new BonusPotViewProxy(tableView.bonusPot_5)];

			tableView.addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			tableView.addEventListener(Event.REMOVED_FROM_STAGE, removeFromStage);
		}

		public function get tableDataModel():TableDataModel
		{
			return TablesDataManager.tableDataModeDic[tableId.toString()];
		}

		private function onAddToStage(event:Event):void
		{
			//更新麻将桌子界面中显示
			dispatcher.addEventListener(MajiangEvent.UPDATE_MAJIANG_TABLE_VIEW, function(event:MajiangEvent):void
			{
				if (tableId.toString() != event.data.tableId.toString())
					return;
				updateMajiangTableView();
			});
			//比赛结束10后清空桌面
			dispatcher.addEventListener(MajiangEvent.CLEAR_TABLE_INFO, function(event:GameEvent):void
			{
				if(tableId.toString() != event.data) return;
				updateMajiangTableView();
			});
		}

		private function removeFromStage(event:Event):void
		{

		}

		/**
		 * 刷新显示
		 **/
		private function updateMajiangTableView():void
		{
			//初始化奖池管理
			if (bonusPotsData != null)
			{
				bonusPotsData.potList = null;
			}
			bonusPotsData = tableDataModel.bonusPotsData;
			bonusPotsData.potList = bonusPotViewProxyList;
		}

	}
}
